const tickTimesMax = 30;
export const ticker = (tick: number, onDone: () => boolean, shouldTimeout: (t: number) => boolean) => (
  () => (
    new Promise<void>(resolve => {
      let tickTimes = 0;
      const t = setInterval(() => {
        if (onDone() || shouldTimeout(tickTimes) || tickTimes > tickTimesMax) {
          clearInterval(t);
          resolve();
        }
        tickTimes += 1;
      }, tick);
    })
  )
);